package com.tecode.gmail.product.controller;

import com.tecode.gmail.bean.Goods;
import com.tecode.gmail.bean.GoodsClassify;
import com.tecode.gmail.bean.GoodsQuery;
import com.tecode.gmail.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created with Intellij IDEA.
 *
 * @Author: Gabriel
 * @Date: 2019-01-03
 * @Description:
 */
@RestController
@RequestMapping("/product")
public class ProductController {

	@Autowired
private ProductService productService;

	/**
	 * 商城首页
	 * @return
	 */
	@GetMapping("/index.html")
	public ModelAndView productIndex(){
		ModelAndView modelAndView = new ModelAndView("html/index");
		//读取商品分类
		List<GoodsClassify> goodsClassifyAll = productService.getGoodsClassifyAll();

		modelAndView.addObject("goodsClassify",goodsClassifyAll);
		return modelAndView;
	}


	/**
	 * 商品查询列表  分类查询列表等等
	 * goodsQuery:用于接收查询条件
	 * @return
	 */
	@GetMapping("/commodity.html")
	public ModelAndView productAllList(GoodsQuery goodsQuery){

		ModelAndView modelAndView = new ModelAndView("html/commodity");
		//读取商品分类
		List<GoodsClassify> goodsClassifyAll = productService.getGoodsClassifyAll();


		//读取当前查询条件下的商品
		List<Goods> iPage = productService.findItemByPage(goodsQuery);



		//封装数据到视图中
		modelAndView.addObject("goodsClassify",goodsClassifyAll);
		modelAndView.addObject("goodsList",iPage);
		modelAndView.addObject("goodsQuery",goodsQuery);

/*		System.out.println("getTotal:" + iPage.getTotal());//总记录数
		System.out.println("getCurrent:"+iPage.getCurrent());//当前页
		System.out.println("getPages:"+iPage.getPages());//总页数
		System.out.println("getRecords:"+iPage.getRecords());//当前页显示内容
		System.out.println("getSize:"+iPage.getSize());//每页显示记录数*/
		return modelAndView;
	}


	@GetMapping("/details.html")
	public ModelAndView getGoodsByGoodsId(Integer goodsId){
		ModelAndView modelAndView = new ModelAndView("html/details");

		return modelAndView;
	}
}